//
//  HLHomeViewModel.swift
//  MyBlog
//
//  Created by 李芙蓉 on 16/3/6.
//  Copyright © 2016年 hanlei. All rights reserved.
//

import UIKit

class HLHomeViewModel: NSObject {
    
    var users : HLUsers = HLUsers()
    
    private lazy var userAccount : HLAccount = {
        
        let path = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).last! as NSString).stringByAppendingPathComponent("keyArchive.archive")
        print(NSHomeDirectory())
        let u = NSKeyedUnarchiver.unarchiveObjectWithFile(path) as! HLAccount
        
        return u
    }()

    
    override init() {
        
        super.init()
        
        getUserInformation()
    }
    
    //发送请求用户信息的函数
    private func getUserInformation () {
        
        let urlString = "https://api.weibo.com/2/statuses/public_timeline.json?\(userAccount.access_token)"
        print(urlString)
        HMNetworkTools.sharedTools.requst(.GET, urlString: urlString, parameters: nil) { (responseObject, error) -> () in
            
            if error == nil {
                
                if let data = responseObject {
                    
                    print(data)
                }
            }
        }
    }
}
